package com.lanswon.qzsmk.controller.inventoryManageController;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lanswon.qzsmk.annotation.SystemControllerLog;
import com.lanswon.qzsmk.exception.InventoryException;
import com.lanswon.qzsmk.service.systemManageService.InventoryManagementService;

import ch.qos.logback.classic.Logger;

@Controller
@RequestMapping(value = "/inventoryMagOfRejectCardTurnInByBranch")
public class InventoryMagOfRejectCardTurnInByBranchController {
	
	private final static Logger logger = (Logger) LoggerFactory.getLogger(InventoryMagOfRejectCardTurnInByBranchController.class);
	
	@Autowired
	InventoryManagementService ims;
	
	
	@RequiresPermissions("inventoryMagOfRejectCardTurnInByBranch:index")
	@RequestMapping(name = "废卡上缴登记页面,inventoryMagOfRejectCardTurnInByBranch:index",value = "/distributionRejectTask", method = {RequestMethod.GET,RequestMethod.POST})
	@SystemControllerLog(description = "跳转到配送画面")
	public String distributionRejectTask() {
		
		return "DistributeByTurnInRejectCard";
	}
	
	/**
	 * 废卡出库登记
	 * @param handtasked
	 * @return
	 * @throws InventoryException 
	 */
	@RequiresPermissions("inventoryMagOfRejectCardTurnInByBranch:saveTurnInRejectCard")
	@RequestMapping(name = "废卡出库登记,inventoryMagOfRejectCardTurnInByBranch:saveTurnInRejectCard",value = "/saveTurnInRejectCard", method = RequestMethod.POST)
	@ResponseBody
	@SystemControllerLog(description = "废卡上缴")
	public Map<String, Object> saveTurnInRejectCard(HttpServletRequest request) throws InventoryException {
		Map<String, Object> rMap = ims.rejectCardTurnInRegister(request);
		Map<String,Object> pramMap = new HashMap<String,Object>();
		pramMap.put("applyType", rMap.get("credential_type"));
		Map<String, Object> map = new HashMap<>();
		map.put("ipAddress", rMap.get("ipAddress"));
		map.put("storageNo", rMap.get("storageNo"));
		map.put("max", "true");
		map.put("title", rMap.get("title"));
		map.put("rel", "distributeToCenter");
		map.put("statusCode", "200");
		map.put("message", "废卡上缴配送成功");
		map.put("param", pramMap);
		map.put("url", "printCredentials/toStoragePdfView");
		
		map.put("jumpToTabid", "cardDistribution");
		map.put("jumpToUrl", "inventoryMagOfRejectCardTurnInByBranch/distributionRejectTask");
		map.put("jumpToTile", "废卡/注销卡上缴配送");
		return map;
	}
}
